// =======================================================================
// 
//       Filename:  processor.hpp
// 
//    Description:  
// 
//        Version:  1.0
//        Created:  09.04.2010 22:35:13
//       Revision:  none
//       Compiler:  g++
// 
//         Author:  Dominik 'domachine' Burgdörfer (-), dominik.burgdoerfer@googlemail.com
//        Company:  -
// 
// =======================================================================


#ifndef  PROCESSOR_INC
#define  PROCESSOR_INC
#include "page.hpp"
#include "plugin.hpp"
#include "template/file.hpp"
#include "template/commandelement.hpp"
#include "template/scriptelement.hpp"
#include "citerator.hpp"
#include "navigation/node.hpp"
#include <stdexcept>

namespace webplodder {
    /**
     * @brief This class processes a Page object and
     *        a Template::File object and produces
     *        an output file.
     */
    class Processor {
    public:
        Processor(std::map<std::string,std::string>&
                         scriptConfig);
        ~Processor();

        /**
         * @brief Process a Template::File object and
         *        a Page object to produce an output
         *        file.
         * @param[in] file The Template::File object
         *                 produced by the Parser
         * @param[in] page The information to fill
         *                 the Template
         */
        void process(const Template::File& file, 
                Page& page);

        /**
         * @brief Installs a Plugin.
         * @param[in] plugin Plugin to install
         */
        void installPlugin(const boost::shared_ptr<Plugin>& 
                plugin);

    private:
        void execSetCmd(const std::vector<boost::any>& args,
                        int line);
        void execNavigationCmd(const std::vector<boost::any>& args,
                               int line,
                               std::ostream& output);
        void execScript(CIterator& input,
                        Template::ScriptElement& script,
                        std::ostream& output);
        void processCmd(CIterator& input,
                        Template::CommandElement& cmd,
                        std::ostream& output);
        void processText(CIterator& input,
                         Template::TextElement& text,
                         std::ostream& output);

        Page* mPage;
        bool mFirstRun;
        std::vector<boost::shared_ptr<Plugin> > mPlugins;
        std::string mTemplateSource;
        std::map<std::string,std::string>* mScriptConfig;
    };
}
#endif   // ----- #ifndef PROCESSOR_INC  -----
